<?php
namespace Home\Controller;
use Think\Controller;
use Think;
/**
* 
*/
class EntranceController extends Controller
{
	//1
	public function Drink($getInfo)
	{
		
		
		//检测openid
		$userModel=D('User');
          //$userModel->checksendOpenid($getInfo['openid'])
		   $return =$userModel->checksendOpenid($getInfo['openid']);
         if ( $return > 0) {
		  	$content = "每个人只能分享一个烦恼哦~";
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            return false;
            exit();
		  }

		
		//
		//if ($getInfo['keyword'] == "喝酒") {
	    	$content = "你需要告诉我们:\n\n【微信号】＋【自我介绍】＋【你的烦恼】\n\n请务必将你的微信号和你的烦恼内容放在一段话内，并检查微信号是否填写正确或遗漏~";//
	    	$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            return true;
            exit();
	    //}
	}
        /**
         * 保存内容
         * @param $getInfo['openid']
         * @param $getInfo['content']
        */
	public function Content($getInfo){
		//再做一次检测 openid
         $userModel=D('User');
         $checkreturn = $userModel->checksendOpenid($getInfo['openid']);
         $totalword=mb_strlen($getInfo['content'],'utf8');//检测字数
         if($checkreturn > 0){
                
                if($totalword<50){
			$content = "北鼻 修改不成功，抱抱你~请描述得更详细一点哦";
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            exit();
            //return false;
		   }

         $return = $userModel->modifyData($getInfo);//保存到数据库中去
			if($return){                       //保持成功
              $content = "北鼻 已收到你修改的烦恼，会尽快安排摆渡人来帮你舒解嗷~\n\n请再次确认你的微信号是否正确，如果填写错误或忘了写，可回复【修改】，修改烦恼内容。";
			  $Transmit = new TransmitController();
              $Transmit->transmitText($getInfo['openid'],$content);
              //return true;
              exit();
			}
		
		}
		else if($totalword<50){
			$content = "北鼻 收到啦，抱抱你~请描述得更详细一点哦";
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            exit();
            //return false;
		}else{
			
			$return = $userModel->saveData($getInfo);//保存到数据库中去
			if($return){                       //保持成功
              $content = "北鼻 已收到你的烦恼，会尽快安排摆渡人来帮你舒解嗷~\n\n请再次确认你的微信号是否正确，如果填写错误或忘了写，可回复【修改】，修改烦恼内容。";
			  $Transmit = new TransmitController();
              $Transmit->transmitText($getInfo['openid'],$content);
              //return true;
              exit();
			}

		}
	}



	
     //~~未测试
	public function Ferryman($getInfo){
		  $userModel=D('User');
		  //加匹配微信号是否获取过两次的判断
          //两次判断

		  if ($userModel->checkOpenid($getInfo['openid']) == false) {
		  	$content = "你已经收到两个烦恼啦，不能再收到新的烦恼了哦";
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            return false;
            exit();
		  }

		  $return = $userModel->findContent($getInfo['openid']);
		  if($return['success'] == false){
		  	$content = "感谢你热心的帮助，现在烦恼都被领取完啦，可以过段时间再来看看哦~";
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            exit();
        }else{
        	$content = "【 你 需 要 做 的 是 】\n1.添加酒客的微信号，添加时备注——\n我是你的摆渡人，来缓解你的烦恼。\n\n2.以下是ta的烦恼及自我介绍：\n".$return['content'];
			$Transmit = new TransmitController();
            $Transmit->transmitText($getInfo['openid'],$content);
            exit();
        }



	}

	public function Modify($getinfo)//修改内容  ‘修改’
	{
		
			
			
			               
              $content = "你需要修改的是:\n\n【微信号】＋【自我介绍】＋【你的烦恼】\n\n请务必将你的微信号和你的烦恼内容放在一段话内，并检查微信号是否填写正确或遗漏~";
			  $Transmit = new TransmitController();
              $Transmit->transmitText($getInfo['openid'],$content);
              exit();
			

		
	}
		
}

?>